package org.JingDong.controller;

import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.SingleResponse;
import com.lizemin.spring.annotation.Autowire;
import com.lizemin.spring.annotation.GetMapping;
import com.lizemin.spring.annotation.RestController;
import lombok.extern.slf4j.Slf4j;
import org.JingDong.entity.Order;
import org.JingDong.service.OrderService;

import java.util.ArrayList;

/**
 * @author lzm
 * @date 2025/4/26 13:05
 * @description
 */
@RestController
@Slf4j
public class OrderController {

    @Autowire
    private OrderService orderService;

    @GetMapping("/orders")
    public MultiResponse<Order> listOrders() {
        ArrayList<Order> orders = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Order order = new Order();
            order.setId(i + 1);
            order.setName("order_" + i + 1);
            orders.add(order);
        }
        return MultiResponse.ofWithoutTotal(orders);
    }

    @GetMapping("/getOrder")
    public SingleResponse<Order> getOrderById(Long id) {
        log.info("接受到的订单id为：{}", id);
        Order order = orderService.getOrderById(id);
        return SingleResponse.of(order);
    }

}
